package com.chexiehui.jc.utils;

import com.alibaba.sdk.android.oss.OSS;
import com.alibaba.sdk.android.oss.OSSClient;
import com.alibaba.sdk.android.oss.common.auth.OSSCredentialProvider;
import com.alibaba.sdk.android.oss.common.auth.OSSStsTokenCredentialProvider;
import com.blankj.utilcode.util.TimeUtils;
import com.chexiehui.jc.AppApplication;

import java.text.SimpleDateFormat;
import java.util.Date;

public class AliossUtil {
//    public static final String END_POINT = "https://oss-cn-beijing.aliyuncs.com";
//    public static final String ACCESS_KEY_ID = "LTAI4Feq5NQ9WcMTwk6ANcef";
//    public static final String SECRET_KEY_ID = "xhmFuvstNUdYIaXJh1j4KLz6CBJLcS";
//    public static final String BUCKET_NAME = AliossUtil.BUCKET_NAME;
//    public static final String IMAGE_PRE = "https://protal.oss-cn-beijing.aliyuncs.com";

    public static final String END_POINT = "http://oss-cn-hangzhou.aliyuncs.com";
    public static final String ACCESS_KEY_ID = "LTAI4G1AiDmNxDhj9N6SfawW";
    public static final String SECRET_KEY_ID = "mWjAmwPCo8FZkn3ZBgdBrmdt5VsAPR";
    public static final String BUCKET_NAME = "cxhoss";
    public static final String IMAGE_PRE = "https://cxhoss.oss-cn-hangzhou.aliyuncs.com";

    public static OSS createOssClient(){
        OSSCredentialProvider credentialProvider = new OSSStsTokenCredentialProvider(
                ACCESS_KEY_ID,
                SECRET_KEY_ID, "");
        OSS ossClient = new OSSClient(AppApplication.getInstances(),
                END_POINT, credentialProvider);
        return ossClient;
    }

    public static String createCarImagePath(String fileName){
        String mCrypt = Md5Util.md5(fileName);
        Date d = TimeUtils.getNowDate();
        String timeStr = TimeUtils.date2String(d, new SimpleDateFormat("yyyyMMdd"));
        String times = d.getTime() + "";
        String mObjectKeyPath = String.format("Image/Android/Car/%s/%s%s.jpg", timeStr, mCrypt, times);
        return mObjectKeyPath;
    }

    public static String createPostImagePath(String fileName){
        String mCrypt = Md5Util.md5(fileName);
        Date d = TimeUtils.getNowDate();
        String timeStr = TimeUtils.date2String(d, new SimpleDateFormat("yyyyMMdd"));
        String times = d.getTime() + "";
        String mObjectKeyPath = String.format("Image/Android/Post/%s/%s%s.jpg", timeStr, mCrypt, times);
        return mObjectKeyPath;
    }

    public static String createCarVideoPath(String fileName){
        String mCrypt = Md5Util.md5(fileName);
        Date d = TimeUtils.getNowDate();
        String timeStr = TimeUtils.date2String(d, new SimpleDateFormat("yyyyMMdd"));
        String times = d.getTime() + "";
        String mObjectKeyPath = String.format("Video/Android/Car/%s/%s%s.jpg", timeStr, mCrypt, times);
        return mObjectKeyPath;
    }

    public static String getEndPointFileUrl(String path){
        return IMAGE_PRE + path;
    }
}
